package com.zzx.utils;

import java.text.ParseException;
import java.util.Date;
import java.text.SimpleDateFormat;

//获取当前时间，返回当前时间的String格式
public class dateUtils {
	public static String getdate() {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date(System.currentTimeMillis());
		return formatter.format(date);
	}

//计算两个时间的时间差，参数为String类的A和B，格式为{yyyy-MM-dd HH:mm:ss}
	public static String timedif(String now, String old) throws ParseException {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		Date nowDate = df.parse(now.toString());

		Date oldDate = df.parse(old.toString());
		long l = Math.abs(nowDate.getTime() - oldDate.getTime());
		int min = (int) (l / (1000 * 60));
		int sec = (int) ((l - min * 60 * 1000) / 1000);
		StringBuffer buffer = new StringBuffer();
		if (min != 0) {
			buffer.append(min).append("分");
		}
		buffer.append(sec).append("秒");
		return buffer.toString();

	}
}
